﻿package com.creawor.hz_market.t_advertisement;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aos.util.UploadFileOne;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import parse.ADHandle;
import parse.AdResHandle;
import parse.AgeHandle;
import parse.BalanceHandle;
import parse.BasestionHandle;
import parse.ChannelHandle;
import parse.ChannelResHandle;
import parse.ChanpingbaoResHandle;
import parse.CheliangHandle;
import parse.ChengbenHandle;
import parse.CommunityHandle;
import parse.CommunityResHandle;
import parse.CountyHandle;
import parse.CustomerResHandle;
import parse.EmployeeHandle;
import parse.GroupAimHandle;
import parse.GroupHandle;
import parse.GroupResHandle;
import parse.GroupjieruResHandle;
import parse.GroupproductHandle;
import parse.GuanxianHandle;
import parse.HallHandle;
import parse.HallsaleHandle;
import parse.JizhanHandle;
import parse.KdproductResHandle;
import parse.KehuHandle;
import parse.KpiHandle;
import parse.LayoutBaseHandle;
import parse.LayoutChannelHandle;
import parse.MarketShareHandle;
import parse.NetBusinessHandle;
import parse.OfficeHandle;
import parse.QuyuhjfbHandle;
import parse.ShouruHandle;
import parse.TownBaseHandle;
import parse.TownBusinessHandle;
import parse.UserHandle;
import parse.WuyeHandle;
import parse.XueliHandle;
import parse.YdproductResHandle;
import parse.t_village_signal_importHandle;

import com.creawor.imei.base.BaseAction;
import com.creawor.imei.util.UUIDGenerator;

public class UploadFileAction extends BaseAction {
	
	
	public String doAdd(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
			throws Exception {
			UploadFileForm vo = (UploadFileForm)form;
			FormFile file = vo.getFile();
			String yeah=request.getParameter("year");
			String month=request.getParameter("month");
			String day=request.getParameter("day");
			
			String date=yeah+"-"+month+"-"+day;
			String rStr="";
			int ii = 0;
			if(file!=null)
			{
			    String rootFilePath = getServlet().getServletContext().getRealPath("/");
			    rootFilePath = (new StringBuilder(String.valueOf(rootFilePath))).append(UploadFileOne.strPath).toString();
			    String strAppend = (new StringBuilder(String.valueOf(UUIDGenerator.nextHex()))).append(UploadFileOne.getFileType(file)).toString();
			    if(file.getFileSize() != 0)
			    {
			        System.out.println("ssssssssssssss"+(ii++));
			        String strReturn = UploadFileOne.fileUploadOne(file, rootFilePath, strAppend);
			        rStr=strReturn;
			        System.out.println("ssssssssssssss"+(ii++));
			        request.setAttribute("imageUploadErrors", strReturn);
			        if(strReturn != null)
			        {
			           // System.out.println((new StringBuilder("\u7167\u7247\u4E0A\u4F20\u5931\u8D25\uFF1A\uFF1A")).append(strReturn).toString());
			        } else
			        {
			            //System.out.println((new StringBuilder("\u91CD\u547D\u540D\u524D\u7684\u6587\u4EF6\u540D\u4E3A\uFF1A\uFF1A")).append(file.getFileName()).append("\u6587\u4EF6\u5927\u5C0F\u4E3A\uFF1A\uFF1A").append(file.getFileSize()).toString());
			            //System.out.println((new StringBuilder("\u6587\u4EF6\u5B8C\u6574\u7684\u8DEF\u5F84\u4E3A\uFF1A")).append(rootFilePath).append(strAppend).toString());
//			            vo.setFile((new StringBuilder(String.valueOf(UploadFileOne.strPath))).append(strAppend).toString());
			            
			         String xmltype = vo.getDoctype();
			       if ("1".equals(xmltype)) {
							BalanceHandle ex=new BalanceHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al=ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertInfo();
						}
						if ("2".equals(xmltype)) {
							CountyHandle ex = new CountyHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(al);
						}
						if ("3".equals(xmltype)) {
							LayoutBaseHandle ex = new LayoutBaseHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(al);
						}
						if ("4".equals(xmltype)) {
							ADHandle ex = new ADHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
								rStr=ex.insertData(al);
						}
						if ("5".equals(xmltype)) {
							
							HallHandle ex = new HallHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("6".equals(xmltype)) {
							HallsaleHandle ex = new HallsaleHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al=ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(al);
							/*ChannelHandle ex=new ChannelHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ex.readExcel(file.getInputStream());
							ex.insertInfo();*/
						}
						if ("7".equals(xmltype)) {
							ChannelHandle ex=new ChannelHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al=ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertInfo();
							
							/*GroupHandle ex = new GroupHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);*/
						}
						if ("8".equals(xmltype)) {
							GroupHandle groupfenH =new GroupHandle();
					        System.out.println("aaaaaaaaaaaaaa"+(ii++));
							ArrayList list=groupfenH.readExcel(file.getFileName(),file.getInputStream());
					        //System.out.println("aaaaaaaaaaaaaa"+(ii++));
							if (list==null){
								rStr= groupfenH.uploadMessage;
								
							}else{
								rStr=groupfenH.insertData(list);
							}
							
					        //System.out.println("bbbbbbbbb"+(ii++));
							/*t_village_signal_importHandle ex = new t_village_signal_importHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);*/
						}
						if ("9".equals(xmltype)) {
							GroupAimHandle groupAimParse=new GroupAimHandle();
							ArrayList rsList=groupAimParse.readExcel(file.getFileName(),file.getInputStream());
							//rStr=groupAimParse.insertData(rsList);
							if (rsList==null)
								rStr= groupAimParse.uploadMessage;
							
							else 
								rStr=groupAimParse.insertData(rsList);
						}
						if ("10".equals(xmltype)) {
							t_village_signal_importHandle ex = new t_village_signal_importHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(al);
							
							/*UserHandle ex = new UserHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							ex.insertData(al);*/
						}
						if ("11".equals(xmltype)) {
							BasestionHandle ex = new BasestionHandle();
							ArrayList rsList=ex.readExcel(file.getFileName(),file.getInputStream());
							/*ex.setString(date);
							rStr=ex.insertData(rsList);*/
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getFileName(),file.getInputStream());
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
								rStr=ex.insertData(al);
							/*GroupfenHandle groupfenH =new GroupfenHandle();
							ArrayList list=groupfenH.readExcel(file.getInputStream());
							groupfenH.insertData(list);*/
							
						}
						if ("12".equals(xmltype)) {
							UserHandle ex = new UserHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al = ex.readExcel(file.getInputStream());
							rStr=ex.insertData(al);
						}
						if ("15".equals(xmltype)) {
							/*GuiHuaChannelHandle ex = new GuiHuaChannelHandle();
							ex.setString(date);
							System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ex.readExcel(file.getInputStream());
							rStr=ex.insertInfo();*/
							LayoutChannelHandle lch=new LayoutChannelHandle();
							ArrayList list=lch.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= lch.uploadMessage;
							
							else 
							rStr=lch.insertData(list);
							
						}
						if ("13".equals(xmltype)) {
							TownBaseHandle townbaseH =new TownBaseHandle();
							ArrayList list=townbaseH.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= townbaseH.uploadMessage;
							
							else 
							rStr=townbaseH.insertData(list);
							
						}
						if ("14".equals(xmltype)) {
							TownBusinessHandle townbH =new TownBusinessHandle();
							ArrayList list=townbH.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= townbH.uploadMessage;
							
							else 
							rStr=townbH.insertData(list);
						}
						
						/*if ("16".equals(xmltype)) {
							GroupMarketHandle ex = new GroupMarketHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList rsList=ex.readExcel(file.getInputStream());
							rStr=ex.insertData(rsList);
						}*/
						if ("17".equals(xmltype)) {
							CommunityHandle ex = new CommunityHandle();
							ex.setString(date);
							//System.out.println("starting....");
//							String filepath = request.getParameter("filepath");
							ArrayList al=ex.readExcel(file.getFileName(),file.getInputStream());
							//rStr=ex.insertData(rsList);
							if (al==null)
								rStr= ex.uploadMessage;
							
							else 
								rStr=ex.insertData(al);
						}
						if ("18".equals(xmltype)) {
							AdResHandle ex = new AdResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("19".equals(xmltype)) {
							CustomerResHandle ex = new CustomerResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("20".equals(xmltype)) {
							ChannelResHandle ex = new ChannelResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						/*if ("21".equals(xmltype)) {
							BusinessResHandle ex = new BusinessResHandle();
							ArrayList list=ex.readExcel(file.getInputStream());
							rStr=ex.insertData(list);
						}*/
						if ("22".equals(xmltype)) {
							GuanxianHandle ex = new GuanxianHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("23".equals(xmltype)) {
							JizhanHandle ex = new JizhanHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("24".equals(xmltype)) {
							GroupResHandle ex = new GroupResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						/*if ("25".equals(xmltype)) {
							NetResHandle ex = new NetResHandle();
							ArrayList list=ex.readExcel(file.getInputStream());
							rStr=ex.insertData(list);
						}*/
						if ("26".equals(xmltype)) {
							NetBusinessHandle ex = new NetBusinessHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("27".equals(xmltype)) {
							EmployeeHandle ex = new EmployeeHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("28".equals(xmltype)) {
							AgeHandle ex = new AgeHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							
							rStr=ex.insertData(list);
						}
						if ("29".equals(xmltype)) {
							XueliHandle ex = new XueliHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("30".equals(xmltype)) {
							OfficeHandle ex = new OfficeHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("31".equals(xmltype)) {
							CheliangHandle ex = new CheliangHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("32".equals(xmltype)) {
							CommunityResHandle ex = new CommunityResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("33".equals(xmltype)) {
							GroupjieruResHandle ex = new GroupjieruResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("34".equals(xmltype)) {
							WuyeHandle ex = new WuyeHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						
						if ("40".equals(xmltype)) {
							YdproductResHandle ex = new YdproductResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("41".equals(xmltype)) {
							KdproductResHandle ex = new KdproductResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("42".equals(xmltype)) {
							ChanpingbaoResHandle ex = new ChanpingbaoResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						//shichangzhang
						if ("35".equals(xmltype)) {
							KpiHandle ex = new KpiHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("36".equals(xmltype)) {
							KehuHandle ex = new KehuHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("37".equals(xmltype)) {
							ShouruHandle ex = new ShouruHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("38".equals(xmltype)) {
							ChengbenHandle ex = new ChengbenHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else 
							rStr=ex.insertData(list);
						}
						if ("39".equals(xmltype)) {
							GroupproductHandle ex = new GroupproductHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						
						if ("43".equals(xmltype)) {
							MarketShareHandle ex = new MarketShareHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("44".equals(xmltype)) {
							QuyuhjfbHandle ex = new QuyuhjfbHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						
						if ("33".equals(xmltype)) {
							GroupjieruResHandle ex = new GroupjieruResHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
						if ("34".equals(xmltype)) {
							WuyeHandle ex = new WuyeHandle();
							ArrayList list=ex.readExcel(file.getFileName(),file.getInputStream());
							if (list==null)
								rStr= ex.uploadMessage;
							
							else
							rStr=ex.insertData(list);
						}
			        }
			    }
			}
			if(rStr==null || "".equals(rStr))
				rStr=file.getFileName()+" 导入成功";
			request.setAttribute("operating-status", rStr);
			System.out.println("in the end....");
			//return "aftersave";
			return "uploadInfo";
		}
	
	
	
	
}
